﻿<div class="layui-card" id="lg-TemplateEdit">
    <div class="layui-card-header">
        <i class="fa fa-home fa-fw"></i>模板添加
        <div class="f-r">
            <button class="layui-btn layui-btn-primary layui-btn-sm" v-on:click="back()"><i class="fa fa-mail-reply fa-fw"></i>返回</button>
        </div>
    </div>
    <div class="layui-card-body">
        <div class="layui-form-item">
            <form class="layui-form layui-form-pane" action="" id="fm_EditTemplate" lay-filter="fm_EditTemplate">
                <div class="layui-form-item hide">
                    <label class="layui-form-label"><i style="color:#f00">*</i>Id</label>
                    <div class="layui-input-block">
                        <input type="text" name="Id" class="layui-input" readonly lay-verify="required" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i>*</i>模板标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="Name" autocomplete="off" placeholder="" class="layui-input" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label"><i>*</i>模板类型</label>
                    <div class="layui-input-block">
                        <input type="radio" name="Type" title="通用" value="0">
                        <input type="radio" name="Type" title="电脑版" value="1" checked="">
                        <input type="radio" name="Type" title="手机版" value="2">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label"><i>*</i>模板类别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="Model" title="列表页" value="1" checked="">
                        <input type="radio" name="Model" title="详情页" value="2">
                        <input type="radio" name="Model" title="公用页" value="0">
                        <input type="radio" name="Model" title="Diy页" value="3">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label"><i>*</i>是否启用</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked="" value="1" name="IsUsing" lay-skin="switch" lay-filter="IsUsing" lay-text="ON|OFF">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">URL</label>
                    <div class="layui-input-block">
                        <input type="text" name="Url" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">模板简介</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" name="Intro" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">模板详情</label>
                    <div class="layui-input-block">
                        <textarea name="Text" style="min-height:600px;font-size:16px;line-height:1.5;" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item text-center">
                    <button class="layui-btn" lay-submit="" lay-filter="bt_EditTemplate">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>

            </form>
        </div>
        <!-- 内容主体区域结束 -->
    </div>
</div>
<script>
    frame.createPage({
        mounted: function() {
            var page = this;
            page.vm = Vue.createApp({
                data() {
                    return {
                        template:[]
                    }
                },
                mounted: function() {
                     this.GetTemplate();
                },
                methods: {
                    back: function() {
                        frame.Back(page.url, res => {
                            res.laytable.reload()
                        })
                    },
                    GetTemplate: function() {
                        lg.request({
                            url: "/api/sys/reserve/GetTemplate",
                            data: { id: @ViewBag.id},
                            success: res => {
                                if (res.code == 0 && res.data != null) {
                                    this.template = res.data;
                                    this.FormRander();
                                } else {
                                    layer.msg("数据获取异常！", { icon: 2 })
                                }
                            }
                        })
                    },
                    FormRander: function() {
                        layui.use(['form'], function() {
                            var form = layui.form
                            form.render();
                            form.val("fm_EditTemplate", page.vm.template);
                            form.on('submit(bt_EditTemplate)', function(d) {
                                var data = d.field;
                                if (!data.IsUsing) {
                                    data.IsUsing = 0
                                }
                                lg.request({
                                    url: "/api/sys/reserve/EditTemplate",
                                    method: "post",
                                    data: data,
                                    success: res => {
                                        if (res.code == 0) {
                                            layer.msg("编辑成功！", { icon: 1 });
                                            page.vm.back();
                                        } else {
                                            layer.msg(res.msg, { icon: 2 })
                                        }
                                    }
                                })
                                return false;
                            })
                        })
                    },
                }
            }).mount("#lg-TemplateEdit")
        },
    }).mount();
</script>
